
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>如何在 SpringMVC中实现文件上传和下载 - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>如何在 SpringMVC中实现文件上传和下载 - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">在Spring MVC中，负责处理文件上传的核心组件是什么？它将HTTP请求中的文件内容解析成哪种对象？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">核心组件是`MultipartResolver`。它负责将HTTP请求中的文件解析成`MultipartFile`对象，以便在控制器中进行处理。</div>
          </div>
          <div class="card-source">来源: 1.1 配置 MultipartResolver</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">安全</div>
          <div class="card-question">为确保文件上传的安全性，文档中提到了哪三项关键的注意事项？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">安全</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">1. 文件大小限制：配置合理的文件大小上限。2. 文件类型校验：验证MIME类型和扩展名，防止恶意文件。3. 存储安全：避免将文件存储在Web可直接访问的目录下，推荐使用非公开目录、数据库或云存储。</div>
          </div>
          <div class="card-source">来源: 1.3 文件上传注意事项</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">在Spring MVC中实现文件下载时，如何设置HTTP响应头以强制浏览器将文件作为附件下载，而不是直接在浏览器中打开？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">通过设置`Content-Disposition`响应头为`attachment`，并指定文件名。例如：`response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");`。</div>
          </div>
          <div class="card-source">来源: 2.2 文件下载注意事项</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">模式</div>
          <div class="card-question">处理大文件下载时，为了避免将整个文件加载到服务器内存中导致溢出，应该采用什么处理方式？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">模式</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">应该在服务器端使用流式处理（Stream processing），通过`InputStream`读取文件并写入到`response.getOutputStream()`，同时可以调用`response.flushBuffer()`来避免内存占用过高。</div>
          </div>
          <div class="card-source">来源: 2.2 文件下载注意事项</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">安全</div>
          <div class="card-question">文档中提到的“路径注入攻击”或“目录遍历攻击”是什么？应如何防范？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">安全</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">这是一种安全漏洞，攻击者通过在请求中提供特殊的文件路径（如`../`）来访问服务器上的非授权文件。防范措施是避免客户端直接提供文件路径，建议使用ID或者哈希值来映射到具体的文件。</div>
          </div>
          <div class="card-source">来源: 3.1 安全性</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">性能</div>
          <div class="card-question">对于高并发的文件上传和下载场景，文档推荐了哪两种策略来提升系统性能和稳定性？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">性能</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">1. 异步处理：使用异步请求或消息队列，避免阻塞主线程。 2. 限流与优化：通过Nginx或其他网关服务对传输速率进行限制，防止服务器资源被耗尽。</div>
          </div>
          <div class="card-source">来源: 3.2 并发与性能</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
